var t = require("../export.js");

getApp();

Page({
    data: {
        isAli: t.dg.os.isAlipay(),
        address: "",
        longitude: 0,
        latitude: 0,
        detail_info: ""
    },
    onLoad: function(t) {
        this.getExplain(t);
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    location: function(n) {
        var a = this;
        t.dg.chooseLocation({
            fail: function(n) {
                a.data.isAli || -1 != n.errMsg.indexOf("auth") && t.dg.confirm("请授权用户地理位置", function(t) {
                    t.confirm && wx.openSetting({
                        success: function(t) {
                            if (t.authSetting) {
                                t.authSetting["scope.userLocation"] && ("请在地图上选点", a.location());
                            }
                        }
                    });
                }, "温馨提示");
            },
            success: function(n) {
                var o = a.data.address;
                o = n.address || "";
                var i = a.data.detail_info;
                n.name && (i = n.name), a.setData({
                    longitude: n.longitude,
                    latitude: n.latitude,
                    address: o,
                    detail_info: i
                }), "" == o && t.dg.alert("请在救援说明中填写完整的地址"), n.address != n.name || a.data.isAli || t.util.getMapSdk().reverseGeocoder({
                    location: {
                        latitude: n.latitude,
                        longitude: n.longitude
                    },
                    success: function(t) {
                        a.setData({
                            address: t.result.address
                        });
                    }
                });
            }
        });
    },
    formSubmit: function(n) {
        var a = this, o = n.detail.value;
        if (o.longitude = 1 * this.data.longitude, o.latitude = 1 * this.data.latitude, 
        o.longitude < .01 || o.latitude < .01) return t.dg.showToast({
            title: "经纬度未获取",
            icon: "none",
            duration: 2e3
        }), !1;
        var i = o;
        console.log(i), t.requestUtil.post(t._DuoguanData.duoguan_host_api_url + "/index.php/addon/DuoguanCar/Apiform/addHelp.html", i, function(t) {
            console.log(t), a.addHelp(t);
        }, this, {});
    },
    addHelp: function(t) {
        wx.showModal({
            title: "提示",
            content: t.info,
            showCancel: !1,
            complete: function(t) {
                wx.navigateTo({
                    url: "/pages/car/helping/helping?flag=1",
                    fail: function(t) {
                        wx.switchTab({
                            url: "/pages/car/index/index"
                        });
                    }
                });
            }
        });
    },
    getExplain: function(n) {
        var a = this;
        t.requestUtil.post(t._DuoguanData.duoguan_host_api_url + "/index.php/addon/DuoguanCar/Api/getExplain.html", n, function(t) {
            console.log(t), a.setData({
                Explain: t.explain,
                coupon: t.coupon
            });
        });
    }
});